package cathe

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"log"
	"shop_srv/appconfig"
)

var ctx = context.Background()
var Rdb *redis.Client

func Init() {
	data := appconfig.ConfigData.Redis
	data_host := fmt.Sprintf("%s:%d", data.Host, data.Port)
	data_password := data.Password
	Rdb = redis.NewClient(&redis.Options{
		Addr:     data_host,
		Password: data_password, // no password set
		DB:       0,             // use default DB
	})

	_, err := Rdb.Ping(ctx).Result()
	if err != nil {
		panic("redis连接失败")
	} else {
	}
	log.Print("redis连接成功")

}
